import Router from 'koa-router';
import { 
  getArticles, 
  getArticleById, 
  createArticle, 
  updateArticle, 
  deleteArticle, 
  changeArticleStatus 
} from '../controllers/article.controller';
import { authMiddleware } from '../middlewares/auth.middleware';
import { roleMiddleware } from '../middlewares/role.middleware';

const router = new Router();

/**
 * @route GET /api/articles
 * @desc 获取文章列表
 * @access Public
 */
router.get('/', getArticles);

/**
 * @route GET /api/articles/:id
 * @desc 获取文章详情
 * @access Public
 */
router.get('/:id', getArticleById);

/**
 * @route POST /api/articles
 * @desc 创建文章
 * @access Private (需要管理员或编辑角色)
 */
router.post('/', authMiddleware, roleMiddleware(['admin', 'editor']), createArticle);

/**
 * @route PUT /api/articles/:id
 * @desc 更新文章
 * @access Private (需要管理员或编辑角色)
 */
router.put('/:id', authMiddleware, roleMiddleware(['admin', 'editor']), updateArticle);

/**
 * @route DELETE /api/articles/:id
 * @desc 删除文章
 * @access Private (需要管理员或编辑角色)
 */
router.delete('/:id', authMiddleware, roleMiddleware(['admin', 'editor']), deleteArticle);

/**
 * @route PATCH /api/articles/:id/status
 * @desc 更改文章状态
 * @access Private (需要管理员或编辑角色)
 */
router.patch('/:id/status', authMiddleware, roleMiddleware(['admin', 'editor']), changeArticleStatus);

export default router; 